/*  Novelties: A visual novel programming language based on JavaFX
    Copyright (C) 2008  Hao Xu

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * /
 
 /*
 * Map.fx
 *
 * Created on Apr 27, 2008, 2:16:19 PM
 */

package avgengine.map;
import avgengine.script.*;
import avgengine.layout.*;
import avgengine.*;
import javafx.ui.canvas.*;
/**
 * @author ertri
 */

class MapDialog extends Sprite {
    attribute gridWidth: int;
    attribute gridHeight: int;
    attribute onClicked: operation (x:int, y:int, k:int);
}
attribute MapDialog.halignment=LEFT;
attribute MapDialog.valignment=TOP;
attribute MapDialog.layoutManager=GridLayout{
    gridHeight: bind gridHeight,
    gridWidth:bind gridWidth
};

attribute MapDialog.onMouseClicked = operation(e:CanvasMouseEvent) {
    var x = (e.x/this.gridWidth).intValue();
    var y = (e.y/this.gridHeight).intValue();
    var func = this.onClicked;
    func(x,y,e.button.intValue());
};

class MapSprite extends Sprite {
    
    attribute gx : int;
    attribute gy: int;
}

attribute MapSprite.halignment = LEFT;
attribute MapSprite.valignment = TOP;

class Map extends Actor {
    attribute gridWidth: int;
    attribute gridHeight: int;
    attribute map: MapDialog;
    operation addSprite(sp:MapSprite);
    attribute onClicked: operation (x:int, y:int, k:int);
}

operation Map.addSprite(sp) {
    map.appendText(SpriteParagraph{topacity:1, sprite:sp, x:sp.gx, y:sp.gy});
}
operation Map.initialize() {
    for(m in music) {
        m.load();
    }
    map = MapDialog{
        imageSet:images
        stage:bind stage
        
        gridHeight: bind gridHeight
        gridWidth:bind gridWidth
        onClicked: bind onClicked
        
    };
    sp = map;
}

LayoutManager{};